package dao;

import org.apache.ibatis.annotations.*;
import pojo.DoctorWork;
import java.util.List;

@Mapper
public interface DoctorWorkMapper {
    @Select("SELECT * FROM doctor_work")
    @Results({
        @Result(column = "day", property = "day"),
        @Result(column = "doc_id", property = "doc_id"),
        @Result(column = "amwork", property = "amwork"),
        @Result(column = "pmwork", property = "pmwork"),
        @Result(column = "create_time", property = "create_time"),
        @Result(column = "weekday", property = "weekday"),
        @Result(column = "fee_id", property = "fee_id"),
        @Result(column = "count_left", property = "count_left")
    })
    List<DoctorWork> findAll();

    @Select("SELECT * FROM doctor_work WHERE doc_id = #{docId} AND day = #{day}")
    @Results({
        @Result(column = "day", property = "day"),
        @Result(column = "doc_id", property = "doc_id"),
        @Result(column = "amwork", property = "amwork"),
        @Result(column = "pmwork", property = "pmwork"),
        @Result(column = "create_time", property = "create_time"),
        @Result(column = "weekday", property = "weekday"),
        @Result(column = "fee_id", property = "fee_id"),
        @Result(column = "count_left", property = "count_left")
    })
    DoctorWork findByDocIdAndDay(@Param("docId") String docId, @Param("day") String day);

    @Insert("INSERT INTO doctor_work(day, doc_id, amwork, pmwork, create_time, weekday, fee_id, count_left) VALUES(#{day}, #{doc_id}, #{amwork}, #{pmwork}, #{create_time}, #{weekday}, #{fee_id}, #{count_left})")
    int add(DoctorWork doctorWork);

    @Update("UPDATE doctor_work SET amwork=#{amwork}, pmwork=#{pmwork}, create_time=#{create_time}, weekday=#{weekday}, fee_id=#{fee_id}, count_left=#{count_left} WHERE doc_id=#{doc_id} AND day=#{day}")
    int update(DoctorWork doctorWork);

    @Delete("DELETE FROM doctor_work WHERE doc_id=#{docId} AND day=#{day}")
    int delete(@Param("docId") String docId, @Param("day") String day);

    @Select("SELECT * FROM doctor_work WHERE doc_id = #{docId}")
    @Results({
        @Result(column = "day", property = "day"),
        @Result(column = "doc_id", property = "doc_id"),
        @Result(column = "amwork", property = "amwork"),
        @Result(column = "pmwork", property = "pmwork"),
        @Result(column = "create_time", property = "create_time"),
        @Result(column = "weekday", property = "weekday"),
        @Result(column = "fee_id", property = "fee_id"),
        @Result(column = "count_left", property = "count_left")
    })
    List<DoctorWork> findByDocId(String docId);
}